package cn.example.vip.mall.canal.dynamic;

import com.dangdang.ddframe.job.reg.zookeeper.ZookeeperConfiguration;
import com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;

public class DynamicConfig {
	
	@Value("${dynamiczk}")
	private String dynamiczk;
	@Value("${dynamicnamespace}")
	private String dynamicnamespace;
	
	/**
	 * 配置注册地址信息
	 * @return
	 */
	@Bean
	public ZookeeperConfiguration zookeeperConfiguration(){
		return new ZookeeperConfiguration(dynamiczk,dynamicnamespace);
	}
	
	/**
	 * 向 zookeeper 注册
	 */
	@Bean(initMethod = "init")
	public ZookeeperRegistryCenter zookeeperRegistryCenter(ZookeeperConfiguration zookeeperConfiguration){
		return new ZookeeperRegistryCenter(zookeeperConfiguration);
	}
	
}
